package com.cqrt.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.cqrt.service.CommonService;
import com.lark.oapi.okhttp.MediaType;
import com.lark.oapi.okhttp.OkHttpClient;
import com.lark.oapi.okhttp.Request;
import com.lark.oapi.okhttp.RequestBody;
import com.lark.oapi.okhttp.Response;
import com.ty.basic.session.TyAccountContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
@Slf4j
public class CommonServiceImpl implements CommonService {

    public String postRequest(String url, String data) throws IOException {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, data);
        Request request = new Request.Builder()
                .url(url)
                .method("POST", body)
                .addHeader("Authorization", TyAccountContext.getToken())
                .addHeader("Content-Type", "application/json")
                .build();
        Response response = client.newCall(request).execute();

        String responseDate = response.body().string();
        log.info("============开始更新项目状态完成,执行结果===================>>:{}", responseDate);
        return responseDate;
    }
}
